package vip.xiaomoli.lock.annotation;

import org.springframework.core.annotation.AliasFor;
import vip.xiaomoli.lock.component.DefaultLockKeyGenerator;
import vip.xiaomoli.lock.component.LockKeyGenerator;
import vip.xiaomoli.lock.constant.LockType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface DistributedLock {

    @AliasFor("bizKeys")
    String[] value() default {};

    /** EL表达式，取方法参数值 */
    @AliasFor("value")
    String[] bizKeys() default {};

    /** 默认[lock:类全名.方法名(String,User)], 配置了bizKeys则拼接[#value1_value2] */
    Class<? extends LockKeyGenerator> keyGenerator() default DefaultLockKeyGenerator.class;

    /** LOCK会一直等待锁，waitSeconds和lockFailMsg不起作用 */
    LockType lockType() default LockType.LOCK;

    /** 等锁时间 */
    long waitSeconds() default 0;

    /** 当LockType=TRY_LOCK，获取锁失败会抛出{@link vip.xiaomoli.lock.exception.LockFailureException} */
    String lockFailMsg() default "Lock Fail";

}
